import isEmpty from 'lodash/isEmpty';
import GLOBAL_CONFIG from '@/common/config';

export function mmvImageUrl(url) {
	if (isEmpty(url)) {
		return url;
	}
	if (url.indexOf('https:') > -1) {
		return url;
	}
	if (url.indexOf('http:') > -1) {
		return url;
	}
	if (url.indexOf('static/') > -1) {
		return url;
	}
	return GLOBAL_CONFIG.baseImageUrl + url;
}

export function bMapToQQMap(lat, lng) {
	let x_pi = (3.14159265358979324 * 3000.0) / 180.0;
	let x = lng - 0.0065;
	let y = lat - 0.006;
	let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
	let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
	let lngs = z * Math.cos(theta);
	let lats = z * Math.sin(theta);
	return [lats, lngs]
}

export function qqMapTobMap(lat, lng) {
	let x_pi = 3.14159265358979324 * 3000.0 / 180.0;
	let x = lng;
	let y = lat;
	let z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
	let theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
	let lngs = z * Math.cos(theta) + 0.0065;
	let lats = z * Math.sin(theta) + 0.006;

	return [lats, lngs]
}

export function strToObj(str){
	let obj = {};
	
	let arr = str.split('&');
	
	arr.forEach(i=>{
		let keys = i.split('=');
		obj[keys[0]]=keys[1];
	})
	return obj;
}
